#include<bits/stdc++.h>
using namespace std;
const int NN=5004,P=998244353;
int a[NN],l[NN],r[NN],f[NN][NN],s[NN][NN];
int main()
{
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		l[i]=i;
		while(l[i]>1&&a[l[i]-1]<=a[i])
			l[i]--;
		r[i]=i;
		while(r[i]<n&&a[r[i]+1]<=a[i])
			r[i]++;
	}
	for(int j=1;j<=n;j++)
		s[0][j]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(i>=l[j]&&i<=r[j])
				f[i][j]=s[i-1][j];
			s[i][j]=(s[i][j-1]+f[i][j])%P;
		}
	printf("%d",s[n][n]);
	return 0;
}
